package com.yu.admin.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yu.admin.modules.system.pojo.UserRole;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @date 2020-11-29 18:17:30
 */
public interface UserRoleMapper extends BaseMapper<UserRole> {
    /**
     * 获取用户角色表
     *
     * @param userId
     */
    @Select("select sys_role.`name` from sys_role " +
            "where sys_role.`id` in (select sys_user_role.`role_id` from sys_user_role where user_id = #{userId})")
    @ResultType(String.class)
    List<String> selectRolesOfUser(Integer userId);

    /**
     * 获取用户权限
     *
     * @param userId
     * @return List<String> 权限表 eg: ["system:user:update", "system:log:*"]
     */
    @Select("select permission from sys_role_permission  " +
            "where role_id in (select sys_user_role.`role_id` from sys_user_role where user_id = #{userId})")
    @ResultType(String.class)
    List<String> selectPermissionsOfUser(Integer userId);
}
